using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class GridDataBound : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;//ConnectionString
            con.Open();
           
            //query that gets only the records needed to the page
            // using the new ROW_NUMBER function in sql2005
            string sql = " SELECT TOP 30 ID_MOVIE,TITLE, GENRE,RATING,VOTES,YEAR" +
                        " FROM TB_MOVIE ";
                     

            SqlCommand cmd = new SqlCommand(sql, con);
          
            SqlDataAdapter adapt = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adapt.Fill(ds);
            //closes the objects and disposes

            //GetMovieCount(ds);
            con.Close();
            cmd.Dispose();
            con.Dispose();
            //YuiGrid1.TotalRecords = GetMovieCount();
            YuiGrid1.DataSource = ds;
            YuiGrid1.DataBind();
        }
       
    }
    private int GetMovieCount()
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;//ConnectionString
        con.Open();
        string sql = "SELECT COUNT(*) FROM TB_MOVIE";
        SqlCommand cmd = new SqlCommand(sql, con);

        int cont = int.Parse(cmd.ExecuteScalar().ToString());
        cmd.Dispose();
        con.Dispose();
        return cont;
    }
}
